﻿using System;
using System.Collections.Generic;
using System.Web;

using Quartz;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

namespace PayRoller.Code
{
    public class SimpleJob:IJob
    {
        #region IJob 成员

        public void Execute(JobExecutionContext context)
        {
            //this.SaveExcuteInfoIntoFile();
            this.SaveExcuteInfoIntoDatabase();
        }

        private void SaveExcuteInfoIntoFile()
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "taskLog.txt";
            using (FileStream fileStream = File.Open(filePath, FileMode.OpenOrCreate))
            {
                using (StreamWriter writer = new StreamWriter(fileStream))
                {
                    writer.WriteLine(DateTime.Now.ToString());
                    writer.Close();
                }
                fileStream.Close();
            }
        }

        private void SaveExcuteInfoIntoDatabase()
        {
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["SQLConnString"]))
            {
                conn.Open();
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection = conn;
                    comm.CommandText = "INSERT INTO TaskExcuteInfo ([TaskName],[ExcuteTime],[memo]) VALUES ('SimpleTask','" + DateTime.Now + "','')";
                    comm.ExecuteNonQuery();
                }
            }
        }

        #endregion
    }
}
